﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.project.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.MapObjectRowMapper;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.project.dao.*;
import com.hh.bss.project.entity.*;
import com.hh.bss.project.service.*;
import com.hh.bss.project.vo.query.*;
import com.hh.bss.util.*;




@Service
@Transactional
public class SearchProjectCompanyServiceImpl extends BaseBusinessService<SearchProjectCompany,java.lang.Integer>  implements SearchProjectCompanyService<SearchProjectCompany,java.lang.Integer>{

	private SearchProjectCompanyDao searchProjectCompanyDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setSearchProjectCompanyDaoImpl(SearchProjectCompanyDao dao) {
		this.searchProjectCompanyDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.searchProjectCompanyDao;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(SearchProjectCompanyQuery query) {
		return searchProjectCompanyDao.findPage(query);
	}

	public Page findProjectCompanyPage(SearchProjectCompanyQuery query) {
		// TODO Auto-generated method stub
		return searchProjectCompanyDao.findProjectCompanyPage(query);
	}

	public List findProjectCustomer(SearchProjectCompanyQuery query) {
		// TODO Auto-generated method stub
		return searchProjectCompanyDao.findProjectCustomer(query);
	}
	
	public List findList(SearchProjectCompanyQuery query) {
		// TODO Auto-generated method stub
		return searchProjectCompanyDao.findList(query);
	}
	
	public Map getProjectCompanyInfo(SearchProjectCompanyQuery query) {
		// TODO Auto-generated method stub
		StringBuffer sql = new StringBuffer();
		List values = new ArrayList();
		sql.append(" select * from ( ");
		sql.append(" select a.name name,a.industrys,a.functions,a.levels,a.cities from search_project a where id=? ");			
		sql.append(" ) t ");
		values.add(query.getProjectId());
		
		
		List l= searchProjectCompanyDao.getJdbcDao().findByQuery(sql.toString(),values.toArray(), new MapObjectRowMapper());
		Map m=new HashMap();
		if (l!=null&&l.size()>0) {
			Map onem=null;
			onem=(Map)l.get(0);
			m.put("level", onem.get("levels"));
			m.put("functions", onem.get("functions"));
			String s=(String)onem.get("functions");
			if (s!=null){
				String[] functions=s.split(",");
				if (functions!=null&&functions.length>0) m.put("function", functions[0]);
			}
			
		}
		sql = new StringBuffer();
		values = new ArrayList();

		sql.append(" select * from ( ");
		sql.append(" select a.industry,a.location  from company a where id=? ");			
		sql.append(" ) t ");
		values.add(query.getCompanyId());
		l= searchProjectCompanyDao.getJdbcDao().findByQuery(sql.toString(),values.toArray(), new MapObjectRowMapper());	
		if (l!=null&&l.size()>0) {
			Map onem=null;
			onem=(Map)l.get(0);
			m.put("industry", onem.get("industry"));
			m.put("location", onem.get("location"));
		}
		
		return m;
	}
	

	
}
